<?
	require("required/dbconnect.php");
	require("required/share_function.php");
	require("required/email.php");
	
	$password=$_POST['password'];
	$email=$_POST['email'];
	$member_card_number=$_POST['member_card_number'];
	$verycode=$_POST['verification_code'];
	$member_type=$_POST['member_type'];
	$name=$_POST['name'];
	$sex=$_POST['sex'];
	$dob=$_POST['dob'];

	$hpnumber=$_POST['hpnumber'];
	$regisdate=date('Y-m-d');
	
	$chkValid=mysql_query("select * from os_member where email='$email' and member_card_number='$member_card_number' and member_type='O'")or die(mysql_error());
	
	$cansubmit=true;
	$msg1="";
	$msg2="";
	$msg3="";

	if($verycode!=$_SESSION['verycode'])
	{
		$msg1="<br><font color='#FF0000'>Sorry,invalid verification code.</font>";
		$cansubmit=false;
	
	}
	
	
	
	if(mysql_num_rows($chkValid)==0)
	{
		$msg3="<br><font color='#FF0000'>Sorry, the data you entered is invalid, please try again.</font>";
		$cansubmit=false;
 	}
	
	if($cansubmit==false)
	{
		require("required/header.php");
?>	
<table width="100%">
<td valign="top" height="400">
	<div class="dw_failed">Invalid</div><br>
	<?= $msg1 ?>
	<?= $msg2 ?>
	<?= $msg3 ?>
	<br><br><br>
	<input type=button value="Back" onClick="history.go(-1)" class="button">
</td>
</table>
<?
	}
if($cansubmit==true){ 
	require("required/function.php"); 
	$activatecode=(generatePassword()*30)+time();
	
	$id=mysql_result($chkValid,0,"id");
		
	$insert=mysql_query("update os_member set password='$password',member_type='N',name='$name',gender='$sex',dob='$dob',hpnumber='$hpnumber',member_type_selected='$member_type',registerdate='$regisdate',status='inactivate',activate_code='$activatecode' where id=$id")or die(mysql_error());
	mysql_query("update os_offline_purchase set member_id='$id' where email='$email'")or die(mysql_error());
	
	$msg="<div class='dw_success'>Thank you for register with us, you are now login as a member.<br>please login into ".$email." for activate your member account. (Please check your junk mail if activation email is not in your inbox)</div>";
	$to=$email; //receiver email here
		
	//------------------------ get data -----------------------------------
	$getid=mysql_query("select * from os_member where email='$email' limit 1");
	$subject=$websitename_eng." member activation";
	$id=mysql_result($getid,0,'id');
	
	
	
	$_SESSION['loginname']=$name;
	$_SESSION['loginid']=$id;
	$_SESSION['email']=$email;
	$_SESSION['member_status']='inactivate';

	if($member_type=="N")
	{	
		email_normal_member_register($id,$activatecode);
	}else{
		email_vip_member_register($id,$activatecode);
	}
	
	header("Location:os_activate_membership3.php?name=$name&email=$email");	
 } 

?>
